package com.zl.csMall.mine.user.controller;

import com.zl.csMall.code.config.token.TokenTriggerAspect;
import com.zl.csMall.mine.user.po.User;
import com.zl.csMall.mine.user.service.UserService;
import com.zl.csMall.vo.ReturnModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @description: UserController
 * @author: ChenNing
 * @date 2025-10-15 13:56
 */
@CrossOrigin(origins = "*")
@Api(tags = "用户")
@RestController
@RequestMapping("csMall/mine/user")
public class UserController {

    @Autowired
    private UserService userService;


    /**
     * @description: 修改用户信息
     * @author ChenNing
     * @date: 2025-10-23 10:55
     */
    @CrossOrigin("*")
    @ApiOperation(value = "修改用户信息")
    @TokenTriggerAspect
    @PutMapping
    public ReturnModel updateUser(@RequestHeader(required = false) String token,
                                  @RequestBody User user){
        if (user == null || user.getId() == 0){
            return new ReturnModel(false, "用户ID不能为空！");
        }
        user.setOpenId(null);
        user.setLoginDate(null);
        user.setIsAdmin(null);
        user.setCreateDate(null);
        user.setUpdateDate(new Date());
        boolean result = userService.updateById(user);
        if (result){
            return new ReturnModel();
        }
        return new ReturnModel(false, "用户信息更新失败！");
    }

}
